<template>
    <div class="updateForm">
        <el-dialog
            title="增加新用户"
            :visible="dialogFormVisible"
            @close="$emit('closeDialog')"
            width="50%"
        >
            <el-form :label-position="labelPosition" label-width="150px" :model="addForm">
                <el-form-item label="账号" :required="true">
                    <el-input v-model="addForm.account"></el-input>
                </el-form-item>
                <el-form-item label="密码" :required="true">
                    <el-input v-model="addForm.password"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="$emit('closeDialog')">取 消</el-button>
                <el-button type="primary" @click="submit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "UserAdd",
    props: ["dialogFormVisible", "addTemp"],
    data() {
        return {
            labelPosition: "right",
            addForm: {
                account: "",
                password: ""
            },
            // uploadApi: "http://127.0.0.1:8000/api/img/uploadImg"
        };
    },
    methods: {
        submit: async function() {
            let data = await this._axios
                .post("/ycwAdmin/admin/add", this.addForm)
                .then(data => data.data);
            console.log(data);
            if (data) {
                this.$alert(`${data.msg}`, {
                    confirmButtonText: "确定",
                    callback: () => {
                        this.$message({
                            type: "warning",
                            message: `${data.msg}`
                        });
                        this.$emit("refresh");
                    }
                })
            }
        }
    },
    watch: {
        addTemp: function(obj) {
            console.log(obj);

            this.addForm = { ...obj };
        }
    }
};
</script>

<style lang="scss">

</style>